/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pio.action.administrador.solicitudes;

import DBMS.DataBaseManager;
import clases.ContactoCoordinador;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author tamerdark
 */
public class ContactoCoordinadorAction extends DispatchAction{
    
    public ActionForward pendientes(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        List solicitudes;
        ContactoCoordinador cc = new ContactoCoordinador();
        cc.setRespondido(false);
        DataBaseManager dbms = DataBaseManager.getInstance();
        solicitudes = dbms.consultarContactoCoordinador(cc);
        request.setAttribute("solicitudes", solicitudes);
        return mapping.findForward("pendientes");
    }

    public ActionForward verDetalle(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ContactoCoordinador cc = (ContactoCoordinador) form;
        List<ContactoCoordinador> solicitudes;
        DataBaseManager dbms = DataBaseManager.getInstance();
        solicitudes = dbms.consultarContactoCoordinador(cc);
        if(solicitudes == null || solicitudes.isEmpty()){
            cc.setMensaje("No se pudo obtener la información de la base de datos. Por favor intentelo más tarde.");
            return mapping.findForward("failure");
        }
        cc.cloneWith(solicitudes.get(0));
        return mapping.findForward("verDetalle");
    }
    
    public ActionForward respondidas(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ContactoCoordinador cc = (ContactoCoordinador) form;
        cc.setRespondido(true);
        List solicitudes;
        DataBaseManager dbms = DataBaseManager.getInstance();
        solicitudes = dbms.consultarContactoCoordinador(cc);
        request.setAttribute("solicitudes", solicitudes);
        return mapping.findForward("respondidas");
    }
    
    public ActionForward eliminar(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ContactoCoordinador cc = (ContactoCoordinador) form;
        DataBaseManager dbms = DataBaseManager.getInstance();
        if(dbms.eliminarContactoCoordinador(cc)){
            return mapping.findForward("eliminar");
        }else{
            cc.setMensaje("Problemas al eliminar la solicitud. Por favor intentelo más tarde.");
            return mapping.findForward("failure");
        }
    }
}
